import {DICT} from '@/services/api'
import {request, METHOD} from '@/utils/request'

/**
 *  查询单个字典
 * @param field 字段名称
 * @returns
 */
export async function single(field) {
    return request(DICT.DICT_SINGLE + `/${field}`, METHOD.GET, {})
}

/**
 *  查询多个字典
 * @param fields
 * @returns Promise<AxiosResponse>
 */
export async function many(fields) {
    return request(DICT.DICT_MANY, METHOD.POST, [...fields])
}

/**
 *
 * @param pageQuery
 * @returns Promise<AxiosResponse>
 */
export async function page(pageQuery) {
    return request(DICT.DICT_PAGE, METHOD.POST, {
        ...pageQuery
    })
}

/**
 *
 * @param id
 * @returns Promise<AxiosResponse>
 */
export async function del(id) {
    return request(DICT.DICT_DELETE + `/${id}`, METHOD.POST, {})
}

/**
 *
 * @param dict
 * @returns Promise<AxiosResponse>
 */
export async function save(dict) {
    return request(DICT.DICT_ADD_OR_UPDATE, METHOD.POST, {
        ...dict,
    })
}

export const columns = [
    {
        title: '字段',
        dataIndex: 'field',
        align: 'center',
    },
    {
        title: '说明',
        dataIndex: 'illustrate',
        align: 'center',
    },
    {
        title: '名称',
        dataIndex: 'name',
        align: 'center',
    },
    {
        title: '取值',
        dataIndex: 'value',
        align: 'center',
    },
    {
        title: '操作',
        align: 'center',
        scopedSlots: {customRender: 'action'}
    }
]
